#ifndef Reader_cxx
#define Reader_cxx

#include "Reader.h"

namespace FPTK{

template<class PixelType,unsigned int Dimension>
reader<PixelType,Dimension>::reader()
{
   loaded=0;
   filename=NULL;
   ptreader=NULL;
   out=&(std::cout);
}

template<class PixelType,unsigned int Dimension>
reader<PixelType,Dimension>::~reader()
{
if(filename!=NULL)
   {
   delete []filename;
   }
}

template<class PixelType,unsigned int Dimension>
int reader<PixelType,Dimension>::SetInput(char *_filename)
{
filename=new char[strlen(_filename)+1];
strcpy(filename,_filename);
return 0;
}


template<class PixelType,unsigned int Dimension>
int reader<PixelType,Dimension>::Update()
{
    if(fopen(filename,"r"))
    {
        ptreader = ReaderType::New();
        ptreader->SetFileName( filename );
        ptreader->Update();
        size=ptreader->GetOutput()->GetLargestPossibleRegion().GetSize();
        loaded=1;
        return 0;
    }
    else
    {
        return -1;
    }
}


template<class PixelType,unsigned int Dimension>
double reader<PixelType,Dimension>::GetSize(int i)
{
    if(i>=0 && i<Dimension)
    {
        return (double)size[i];
    }
    return 0;
}

template<class PixelType,unsigned int Dimension>
typename reader<PixelType,Dimension>::ImageType* reader<PixelType,Dimension>::GetOutput()
{
if(loaded)
   {
   return ptreader->GetOutput();
   }
else
   {
   (*out)<<"No Image Loaded"<<std::endl;
   }
return NULL;
}

template<class PixelType,unsigned int Dimension>
char* reader<PixelType,Dimension>::GetName()
{
if(loaded)
   {
   return filename;
   }
else
   {
   (*out)<<"No Image Loaded"<<std::endl;
   }
return NULL;
}

template<class PixelType,unsigned int Dimension>
bool reader<PixelType,Dimension>::IsLoaded()
{
return loaded;
}

}//end of FPTK namespace
#endif